import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { Router, ActivatedRoute, NavigationExtras} from '@angular/router';
import { BusinessCircleService } from '../business-circle.service';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { defalutImg } from '../comm';
import { PermissionService } from '../../../service/permission.service';

@Component({
  selector: 'app-report-record',
  templateUrl: './report-record.component.html',
  styleUrls: ['./report-record.component.scss']
})
export class ReportRecordComponent implements OnInit {

  // seachForm
  seachParams: any = {
    reason: '' // 举报原因
  };
  // 举报原因：广告或垃圾信息、低俗或色情信息、政治敏感、人身攻击、有害信息、内容侵权、恶意刷帖、其他
  reasonOptions: any = [
    { label: '广告或垃圾信息', value: '0' },
    { label: '低俗或色情信息', value: '1' },
    { label: '政治敏感', value: '2' },
    { label: '人身攻击', value: '3' },
    { label: '有害信息', value: '4' },
    { label: '内容侵权', value: '5' },
    { label: '恶意刷帖', value: '6' },
    { label: '其他', value: '7' }
  ];

  // table
  tableForms: any = {
    tableLoading: false,
    page: 1,
    pageSize: 20,
    total: 0,
    pages: 0
  };
  // 表格data
  tableData: any = [];
  routeParams: any = {};

  constructor(
    private fb: FormBuilder,
    private message: NzMessageService,
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private services: BusinessCircleService,
    public permission: PermissionService,
  ) {
    this.activatedRoute.params.subscribe((res: any) => {
      this.routeParams = res;
    });
  }

  ngOnInit(): void {
    this.loadTable();
  }

  async loadTable() {
    try {
      this.tableForms.tableLoading = true;
      const res: any = await this.services.queryReportDetailTableData({ ...this.seachParams, id: this.routeParams.id });
      this.tableForms.tableLoading = false;
      if (res.code == 0) {
        this.tableData = res.data || [];
      }
    } catch (error: any) {
      this.tableForms.tableLoading = false;
      this.tableData = [];
      // console.log(error);
    }
  }

  // 查询
  queryData() {
    this.tableForms.page = 1;
    this.loadTable();
  }
  // 重置
  resetData() {
    this.seachParams.reason = '';
    this.tableForms.page = 1;
    this.loadTable();
  }

  // 当前页码改变时的回调函数
  onPageIndexChange(index: number) {
    this.tableForms.page = index;
    this.loadTable();
  }
  // 页数改变时回调
  onPageSizeChange(sizeNum: number) {
    this.tableForms.page = 1;
    this.tableForms.pageSize = sizeNum;

    this.loadTable();
  }
}
